﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Zocono.WCS.Domain.DomainRepository;
using Zocono.WCS.Domain.EntityInfo;
using Zocono.WCS.Infrastructure.ApllicationDto;
using Zocono.WCS.Infrastructure.ApllicationDto.DtoWcsManage;
using Zocono.WMS.Infrastructure.BaseRepository;

namespace Zocono.WCS.Infrastructure.Repository
{
    public class ElevatorMasterInfoRepository : BaseRepository<ElevatorMasterInfo>, IElevatorMasterInfoRepository
    {
        public ElevatorMasterInfoRepository(SqlSugarClient context = null) : base(context)
        {

        }

        public  async Task<PageDto<ElevatorMasterInfoDto>> GetElevatorMasterInfosAsync(Expression<Func<ElevatorMasterInfo, bool>> exp, PageModel page)
        {
            PageDto<ElevatorMasterInfoDto> pageDto = new PageDto<ElevatorMasterInfoDto>();
            RefAsync<int> totalNumber = 0;
            var result = await Context.Queryable<ElevatorMasterInfo>()
                .Where(exp)
                .Select(l => new ElevatorMasterInfoDto
                {
                    ID = l.ID,
                    ElevatorCode = l.ElevatorCode,
                    NextElevatorCodes = l.NextElevatorCodes,
                    ElevatorDOCodes = l.ElevatorDOCodes,
                    ElevatorPUCode = l.ElevatorPUCode,
                    CrossroadEquipmentCode = l.CrossroadEquipmentCode,
                    CanToEquipments = l.CanToEquipments,
                    IsEnable =l.IsEnable
                } ).ToPageListAsync(page.PageIndex, page.PageSize, totalNumber);

            pageDto.Result = result;
            pageDto.Total = totalNumber;
            return pageDto;
        }
    }
}
